//
//  NRWUserInfoModel.m
//  NRWMall
//
//  Created by 邢毅 on 2018/6/14.
//  Copyright © 2018年 com.anpxd. All rights reserved.
//

#import "NRWUserInfoModel.h"

static NRWUserInfoModel *model;

@interface NRWUserInfoModel()

@end

@implementation NRWUserInfoModel

+ (instancetype)shared {
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        model = [[NRWUserInfoModel alloc] init];
        [model setValuesForKeysWithDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:@"userDict"]];
    });
    return model;
}

+ (void)setValueForUserInfoDict:(NSDictionary *)dict {
    
    NRWUserInfoModel *m = [NRWUserInfoModel shared];
    [m setValuesForKeysWithDictionary:dict];
    [[NSUserDefaults standardUserDefaults] setObject:dict forKey:@"userDict"];
}

+ (void)resetUserInfo {
    
    model.userMobile = nil;
    model.userCreateTime = nil;
    model.userId = nil;
    model.userSource = nil;
    model.userToken = nil;
    model.userUpdateTime = nil;
    
    [[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"userDict"];
    [[NSUserDefaults standardUserDefaults] setObject:nil forKey:authorizationKey];
}

- (BOOL)isLogin {
    return isNotEmptyString(self.userId);
}

- (id)copyWithZone:(NSZone *)zone {
    
    return model;
}

- (instancetype)init
{
    if (self == model) {
        return self;
    }
    self = [super init];
    if (self) {
        
    }
    return self;
}

@end
